﻿using mediaControl.Event;
using mediaControl.Utils;
using mediaControl.Vo;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Transitionals.Controls;
using Image = System.Windows.Controls.Image;

namespace mediaControl.ViewModels
{
    public class Monitor1ViewModel : BindableBase
    {
        //事件聚合器
        private readonly IEventAggregator _eventAggregator;

        private ScreenVo screenVo;

        private string cycleModel;

        private List<ProgramItem> currentProgramList;

        public MediaElement videoPlayer;

        private UserControl userControl;

        public Image imagePlayer;

        public Grid webBrowser;

        private string videoSrc;

        private string imageSrc;

        private List<string> imagePaths;

        private DispatcherTimer timer = new DispatcherTimer();
        private DispatcherTimer timer2 = new DispatcherTimer();

        //图片标签显示标志
        private Visibility imageFlag = Visibility.Hidden;

        //视频标签显示标志
        private Visibility videoFlag = Visibility.Hidden;

        //网页框显示标志
        private Visibility webFlag = Visibility.Hidden;

        private TranslateTransform translateTransform;

        private ScaleTransform scaleTransform;

        private TranslateTransform translateTransformNext;

        private ScaleTransform scaleTransformNext;


        private Image imagePlayerNext;

        private double opacity = 1;

        private string exitMethod;

        private IRegionManager _regionManager;

        public Visibility ImageFlag { get { return imageFlag; } set { this.imageFlag = value; RaisePropertyChanged(); } }

        public Visibility VideoFlag { get { return videoFlag; } set { this.videoFlag = value; RaisePropertyChanged(); } }

        public string VideoSrc { get { return videoSrc; } set { this.videoSrc = value; RaisePropertyChanged(); } }

        public string ImageSrc { get { return imageSrc; } set { this.imageSrc = value; RaisePropertyChanged(); } }

        public DelegateCommand<Object> MediaEndedCommand { get; set; }
        public Visibility WebFlag { get { return webFlag; } set { this.webFlag = value; RaisePropertyChanged(); } }

        private string webUrl;

        public string WebUrl { get { return webUrl; } set { this.webUrl = value; RaisePropertyChanged(); } }

        public double Opacity { get { return opacity; } set { this.opacity = value; RaisePropertyChanged(); } }

        public Image ImagePlayer { get { return imagePlayer; } set { this.imagePlayer = value; RaisePropertyChanged(); } }
        public MediaElement VideoPlayer { get { return videoPlayer; } set { this.videoPlayer = value; RaisePropertyChanged(); } }
        public Grid WebBrowser { get { return webBrowser; } set { this.webBrowser = value; RaisePropertyChanged(); } }
        public TranslateTransform TranslateTransform { get { return translateTransform; } set { this.translateTransform = value; RaisePropertyChanged(); } }
        public ScaleTransform ScaleTransform { get { return scaleTransform; } set { this.scaleTransform = value; RaisePropertyChanged(); } }

        public UserControl UserControl { get => userControl; set => userControl = value; }
        public Image ImagePlayerNext { get => imagePlayerNext; set => imagePlayerNext = value; }
        public ScaleTransform ScaleTransformNext { get => scaleTransformNext; set => scaleTransformNext = value; }
        public TranslateTransform TranslateTransformNext { get => translateTransformNext; set => translateTransformNext = value; }
        public TransitionElement ImageTran { get => imageTran; set => imageTran = value; }

        public Monitor1ViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
        {
            _eventAggregator = eventAggregator;
            _regionManager = regionManager;
            _eventAggregator.GetEvent<Monitor1Event>().Subscribe(PlaySource);
            _eventAggregator.GetEvent<ClearPlaySourceEvent>().Subscribe(ClearSource);
            _eventAggregator.GetEvent<MonitorCleanUpEvent>().Subscribe(CleanUpMonitor);
            _eventAggregator.GetEvent<PlayStatusEvent>().Subscribe(pauseSource);
            _eventAggregator.GetEvent<ClearMonitor1Event>().Subscribe(ClearSource);
            MediaEndedCommand = new DelegateCommand<object>(mediaEnded);
            timer.Tick += Timer_Tick;
            timer2.Tick += Timer2_Tick;
            screenVo = new ScreenVo();
            screenVo.Width = 230;
            screenVo.Height = 200;
        }

        private void CleanUpMonitor(List<string> screenIds)
        {
            if (null != screen && !screenIds.Contains(screen.Id + ""))
            {
                if (null != VideoPlayer)
                {
                    VideoPlayer.Stop();
                    VideoPlayer.Source = null;
                    VideoPlayer.Visibility = Visibility.Hidden;
                }
                if (null != WebBrowser && WebBrowser.Children.Count > 0)
                {
                    webBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
                }
                if (null != ImagePlayer)
                {
                    ImagePlayer.Visibility = Visibility.Hidden;
                    ImagePlayer.Source = null;
                }
                if (null != imagePlayerNext)
                {
                    imagePlayerNext.Visibility = Visibility.Hidden;
                    imagePlayerNext.Source = null;
                }
                if (null != imageTran)
                {
                    imageTran.Content = null;
                    imageTran.Visibility = Visibility.Hidden;
                }
                timer.Stop();
                timer1.Stop();
                timer2.Stop();

            }
        }

        private void Timer2_Tick(object sender, EventArgs e)
        {

            if (null != ImagePlayer)
            {
                var screenSize = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                using (var bmp = new Bitmap(screenSize.Width, screenSize.Height))
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), screenSize.Size);
                    }

                    IntPtr hBitmap = bmp.GetHbitmap();
                    try
                    {
                        _desktopImage = Imaging.CreateBitmapSourceFromHBitmap(
                            hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                        // 更新UI
                        ImagePlayer.Source = _desktopImage;

                    }
                    finally
                    {
                        NativeMethods.DeleteObject(hBitmap); // 释放资源
                    }
                }

            }
        }

        private BitmapSource _desktopImage;
        public static class NativeMethods
        {
            [System.Runtime.InteropServices.DllImport("gdi32.dll")]
            [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
            public static extern bool DeleteObject(IntPtr hObject);
        }

        private void ClearSource()
        {
            if (null != VideoPlayer)
            {
                VideoPlayer.Stop();
                VideoPlayer.Source = null;
                VideoPlayer.Visibility = Visibility.Hidden;
            }
            if (null != WebBrowser && WebBrowser.Children.Count > 0)
            {
                webBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
            }
            if (null != ImagePlayer)
            {
                ImagePlayer.Visibility = Visibility.Hidden;
                ImagePlayer.Source = null;
            }
            if (null != imagePlayerNext)
            {
                imagePlayerNext.Visibility = Visibility.Hidden;
                imagePlayerNext.Source = null;
            }
            if (null != imageTran)
            {
                imageTran.Content = null;
                imageTran.Visibility = Visibility.Hidden;
            }
            timer.Stop();
            timer1.Stop();
            timer2.Stop();
        }

        string type;

        private void pauseSource(string obj)
        {
            if (obj.Equals("1"))
            {
                if (null != VideoPlayer)
                {
                    VideoPlayer.Play();
                }
                if (null != ImagePlayer && null != ImagePlayer.Source)
                {
                    if ("2".Equals(type))
                    {
                        timer.Start();
                    }
                    else if ("6".Equals(type))
                    {
                        timer2.Start();
                    }
                }
            }

            if (obj.Equals("0"))
            {
                if (null != VideoPlayer)
                {
                    videoPlayer.Pause();
                }
                if (null != ImagePlayer)
                {
                    timer.Stop();
                    timer1.Stop();
                    timer2.Stop();
                }
            }
            if (obj.Equals("-1"))
            {
                if (null != VideoPlayer)
                {
                    VideoPlayer.Stop();
                }
                timer.Stop();
                timer1.Stop();
                timer2.Stop();

            }
            if (obj.Equals("-2"))
            {

                if (null != VideoPlayer)
                {
                    VideoPlayer.Stop();
                    VideoPlayer.Source = null;
                    VideoPlayer.Visibility = Visibility.Hidden;
                }
                if (null != WebBrowser && WebBrowser.Children.Count > 0)
                {
                    webBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
                }
                if (null != ImagePlayer)
                {
                    ImagePlayer.Visibility = Visibility.Hidden;
                    ImagePlayer.Source = null;
                }
                if (null != imagePlayerNext)
                {
                    imagePlayerNext.Visibility = Visibility.Hidden;
                    imagePlayerNext.Source = null;
                }
                if (null != imageTran)
                {
                    imageTran.Content = null;
                    imageTran.Visibility = Visibility.Hidden;
                }
                timer.Stop();
                timer1.Stop();
                timer2.Stop();
            }
        }
        private int index = 0;
        private void mediaEnded(object obj)
        {
            videoPlayer = obj as MediaElement;
            videoPlayer.Stop();
            switch (cycleModel)
            {
                case "1":
                    index++;
                    if (index < currentProgramList.Count)
                    {
                        VideoPlayer.Source = new Uri(currentProgramList[index].ItemPath);
                        if (currentProgramList[index].IsMute)
                        {
                            videoPlayer.Volume = 0;
                        }
                        VideoPlayer.Play();
                        if (String.IsNullOrEmpty(currentProgramList[index].DisplayMode) || currentProgramList[0].DisplayMode.Equals("1"))
                        {
                            //全屏

                            if (null != VideoPlayer)
                            {
                                VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                            }

                        }
                        if (!String.IsNullOrEmpty(currentProgramList[index].DisplayMode) && currentProgramList[0].DisplayMode.Equals("2"))
                        {
                            //视屏自身生比例

                            VideoPlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                        }
                        if (!String.IsNullOrEmpty(currentProgramList[index].DisplayMode) && currentProgramList[0].DisplayMode.Equals("3"))
                        {
                            //16:9
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 16 / 9);
                            }

                            VideoPlayer.Height = newHeight;
                            VideoPlayer.Width = newWidth;
                            VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        if (!String.IsNullOrEmpty(currentProgramList[index].DisplayMode) && currentProgramList[0].DisplayMode.Equals("4"))
                        {
                            //4:3
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 4 / 3);
                            }

                            VideoPlayer.Height = newHeight;
                            VideoPlayer.Width = newWidth;
                            VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                    }
                    else
                    {
                        timer.Stop();
                    }
                    break;
                default:
                    index++;
                    if (index >= currentProgramList.Count)
                    {
                        index = 0;
                    }
                    VideoPlayer.Source = new Uri(currentProgramList[index].ItemPath);
                    if (currentProgramList[index].IsMute)
                    {
                        VideoPlayer.Volume = 0;
                    }
                    if (String.IsNullOrEmpty(currentProgramList[index].DisplayMode) || currentProgramList[0].DisplayMode.Equals("1"))
                    {
                        //全屏

                        if (null != VideoPlayer)
                        {

                            VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }

                    }
                    if (!String.IsNullOrEmpty(currentProgramList[index].DisplayMode) && currentProgramList[0].DisplayMode.Equals("2"))
                    {
                        //视屏自身生比例
                        VideoPlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                    }
                    if (!String.IsNullOrEmpty(currentProgramList[index].DisplayMode) && currentProgramList[0].DisplayMode.Equals("3"))
                    {
                        //16:9
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 16 / 9);
                        }

                        VideoPlayer.Height = newHeight;
                        VideoPlayer.Width = newWidth;
                        VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    if (!String.IsNullOrEmpty(currentProgramList[index].DisplayMode) && currentProgramList[0].DisplayMode.Equals("4"))
                    {
                        //4:3
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 4 / 3);
                        }

                        VideoPlayer.Height = newHeight;
                        VideoPlayer.Width = newWidth;
                        VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    VideoPlayer.Play();
                    VideoPlayer.Visibility = Visibility.Visible;

                    break;
            }
        }

        List<string> exitModes = new List<string>();
        private List<int> stopTimes = new List<int>();
        private List<string> displayModes = new List<string>();
        private string displayMode;

        ScreenVo screen;
        private void PlaySource(PlaySourceNewVo obj)
        {

            screen = obj.PlaySources[0].Screen;
            currentProgramList = new List<ProgramItem>();
            //ImageFlag = Visibility.Hidden;
            //WebFlag = Visibility.Hidden;
            //VideoFlag = Visibility.Hidden;
            /*
            if (null != VideoPlayer)
            {
                VideoPlayer.Stop();
                VideoPlayer.Source = null;
            }
            if (null != WebBrowser && WebBrowser.Children.Count > 0)
            {
                WebBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
            }*/
            timer.Stop();
            timer1.Stop();
            timer2.Stop();
            cycleModel = obj.CycleModel;
            exitMethod = obj.PlaySources[0].SouceItem.ExitMethod;
            type = obj.PlaySources[0].Type;
            switch (type)
            {
                case "1":
                    //播放视频

                    VideoPlayer.Visibility = Visibility.Visible;



                    index = 0;


                    foreach (PlaySourceVo playSourceVo in obj.PlaySources)
                    {
                        if (File.Exists(playSourceVo.SouceItem.ItemPath))
                        {
                            currentProgramList.Add(playSourceVo.SouceItem);
                        }
                    }
                    if (String.IsNullOrEmpty(currentProgramList[0].DisplayMode) || currentProgramList[0].DisplayMode.Equals("1"))
                    {
                        //全屏
                        //CurrentWindow.WindowState = WindowState.Maximized;
                        //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                        //CurrentWindow.WindowStyle = WindowStyle.None;
                        if (null != VideoPlayer)
                        {

                            VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;

                        }

                    }
                    if (!String.IsNullOrEmpty(currentProgramList[0].DisplayMode) && currentProgramList[0].DisplayMode.Equals("2"))
                    {
                        //视屏自身生比例

                        VideoPlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                    }
                    if (!String.IsNullOrEmpty(currentProgramList[0].DisplayMode) && currentProgramList[0].DisplayMode.Equals("3"))
                    {
                        //16:9

                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 16 / 9);
                        }

                        VideoPlayer.Height = newHeight;
                        VideoPlayer.Width = newWidth;
                        VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    if (!String.IsNullOrEmpty(currentProgramList[0].DisplayMode) && currentProgramList[0].DisplayMode.Equals("4"))
                    {
                        //4:3
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 4 / 3);
                        }

                        VideoPlayer.Height = newHeight;
                        VideoPlayer.Width = newWidth;
                        VideoPlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    VideoSrc = currentProgramList[0].ItemPath;
                    if (currentProgramList[0].IsMute)
                    {
                        VideoPlayer.Volume = 0;
                    }
                    videoPlayer.Source = new Uri(VideoSrc);
                    videoPlayer.Play();

                    break;
                case "2":

                    ImagePlayer.Visibility = Visibility.Visible;
                    imagePlayer.Visibility = Visibility.Visible;
                    imagePlayerNext.Visibility = Visibility.Hidden;
                    imageTran.Visibility = Visibility.Hidden;
                    imagePaths = new List<string>();
                    exitModes = new List<string>();
                    stopTimes = new List<int>();
                    displayModes = new List<string>();
                    foreach (PlaySourceVo playSourceVo in obj.PlaySources)
                    {
                        currentProgramList.Add(playSourceVo.SouceItem);
                        if (Directory.Exists(playSourceVo.SouceItem.ItemPath))
                        {
                            //文件夹
                            imagePaths.AddRange(getImageList(playSourceVo.SouceItem.ItemPath));
                            foreach (string path in imagePaths)
                            {
                                exitModes.Add(string.IsNullOrEmpty(playSourceVo.SouceItem.ExitMethod) ? "0" : playSourceVo.SouceItem.ExitMethod);
                                stopTimes.Add(playSourceVo.SouceItem.ResidenceTime == 0 ? 5 : playSourceVo.SouceItem.ResidenceTime);
                                displayModes.Add(String.IsNullOrEmpty(playSourceVo.SouceItem.DisplayMode) ? "1" : playSourceVo.SouceItem.DisplayMode);
                            }
                        }
                        else
                        {
                            if (File.Exists(playSourceVo.SouceItem.ItemPath))
                            {
                                imagePaths.Add(playSourceVo.SouceItem.ItemPath);
                                exitModes.Add(string.IsNullOrEmpty(playSourceVo.SouceItem.ExitMethod) ? "0" : playSourceVo.SouceItem.ExitMethod);
                                stopTimes.Add(playSourceVo.SouceItem.ResidenceTime == 0 ? 5 : playSourceVo.SouceItem.ResidenceTime);
                                displayModes.Add(String.IsNullOrEmpty(playSourceVo.SouceItem.DisplayMode) ? "1" : playSourceVo.SouceItem.DisplayMode);
                            }
                        }
                    }

                    if (null == imagePaths || imagePaths.Count <= 0)
                    {
                        return;
                    }

                    //图片
                    if (null != imagePaths && imagePaths.Count > 1)
                    {
                        //处理屏幕
                        displayMode = displayModes[0];

                        if (displayMode.Equals("1"))
                        {
                            //全屏
                            //CurrentWindow.WindowState = WindowState.Maximized;
                            //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                            //CurrentWindow.WindowStyle = WindowStyle.None;

                            ImagePlayer.Width = 230;
                            ImagePlayer.Height = 200;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                        }
                        if (displayMode.Equals("2"))
                        {
                            //视屏自身生比例
                            ImagePlayer.Width = 230;
                            ImagePlayer.Height = 200;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                        }
                        if (displayMode.Equals("3"))
                        {
                            //16:9
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 16 / 9);
                            }

                            ImagePlayer.Height = newHeight;
                            ImagePlayer.Width = newWidth;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        if (displayMode.Equals("4"))
                        {
                            //4:3
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 4 / 3);
                            }

                            ImagePlayer.Height = newHeight;
                            ImagePlayer.Width = newWidth;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        timer.Interval = TimeSpan.FromSeconds(stopTimes[0]);

                        ImageSrc = imagePaths[0];
                        ImagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                        //FadeIn();
                        //SlideLeftImageIn();
                        //ShutterImageIn();
                        imageCenter(imagePlayer);
                        exitMethod = exitModes[0];
                        switch (exitMethod)
                        {
                            case "1":
                                Opacity = 0;
                                FadeIn();
                                break;
                            case "2":
                                Opacity = 1;
                                SlideLeftImageIn();
                                break;
                            case "3":
                                Opacity = 1;
                                SlideRightImageIn();
                                break;
                            case "4":
                                Opacity = 1;
                                SlideUpImageIn();
                                break;
                            case "5":
                                Opacity = 1;
                                SlideDownImageIn();
                                break;
                            case "6":
                                Opacity = 1;
                                ShutterImageIn();
                                break;
                            case "7":
                                Opacity = 1;
                                ScaleImageIn();
                                break;
                            case "8":
                                InitRandomImage();
                                break;
                            default:
                                break;

                        }
                        imageIndex = 0;
                        timer.Start();
                    }
                    else
                    {
                        ImagePlayerNext.Visibility = Visibility.Hidden;
                        imagePlayerNext.Source = null;
                        //处理屏幕
                        displayMode = displayModes[0];

                        if (displayMode.Equals("1"))
                        {
                            //全屏
                            //CurrentWindow.WindowState = WindowState.Maximized;
                            //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                            //CurrentWindow.WindowStyle = WindowStyle.None;

                            ImagePlayer.Width = 230;
                            ImagePlayer.Height = 200;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                        }
                        if (displayMode.Equals("2"))
                        {
                            //视屏自身生比例
                            ImagePlayer.Width = 230;
                            ImagePlayer.Height = 200;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                        }
                        if (displayMode.Equals("3"))
                        {
                            //16:9
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 16 / 9);
                            }

                            ImagePlayer.Height = newHeight;
                            ImagePlayer.Width = newWidth;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        if (displayMode.Equals("4"))
                        {
                            //4:3
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 4 / 3);
                            }

                            ImagePlayer.Height = newHeight;
                            ImagePlayer.Width = newWidth;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        ImageSrc = imagePaths[0];
                        ImagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                        exitMethod = exitModes[0];
                        switch (exitMethod)
                        {
                            case "1":
                                Opacity = 0;
                                FadeIn();
                                break;
                            case "2":
                                Opacity = 1;
                                SlideLeftImageIn();
                                break;
                            case "3":
                                Opacity = 1;
                                SlideRightImageIn();
                                break;
                            case "4":
                                Opacity = 1;
                                SlideUpImageIn();
                                break;
                            case "5":
                                Opacity = 1;
                                SlideDownImageIn();
                                break;
                            case "6":
                                Opacity = 1;
                                ShutterImageIn();
                                break;
                            case "7":
                                Opacity = 1;
                                ScaleImageIn();
                                break;
                            default:
                                break;

                        }
                        imageCenter(imagePlayer);
                    }
                    WebBrowser.Visibility = Visibility.Hidden;
                    VideoPlayer.Visibility = Visibility.Hidden;
                    if (null != WebBrowser && WebBrowser.Children.Count > 0)
                    {
                        WebBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
                    }
                    VideoPlayer.Stop();
                    VideoPlayer.Source = null;

                    break;
                case "4":
                    WebBrowser.Visibility = Visibility.Visible;
                    foreach (PlaySourceVo playSourceVo in obj.PlaySources)
                    {
                        currentProgramList.Add(playSourceVo.SouceItem);
                    }
                    WebBrowser.Visibility = Visibility.Visible;

                    WebUrl = currentProgramList[0].ItemPath;
                    if (!CefSharp.Cef.IsInitialized)
                    {
                        var setting = new CefSharp.CefSettings();
                        setting.CefCommandLineArgs.Add("disable-gpu", "1");
                        CefSharp.Cef.Initialize(setting);//这个函数可能后面还有两个参数
                    }
                    var webView = new CefSharp.Wpf.ChromiumWebBrowser();
                    webView.Address = WebUrl;
                    WebBrowser.Children.Add(webView);
                    Thread.Sleep(500);
                    ImagePlayer.Visibility = Visibility.Hidden;
                    VideoPlayer.Visibility = Visibility.Hidden;
                    if (null != imagePlayerNext)
                    {
                        imagePlayerNext.Visibility = Visibility.Hidden;
                        imagePlayerNext.Source = null;
                    }
                    if (null != imageTran)
                    {
                        imageTran.Content = null;
                        imageTran.Visibility = Visibility.Hidden;
                    }
                    ImagePlayer.Source = null;
                    VideoPlayer.Source = null;
                    VideoPlayer.Stop();
                    break;
                case "6":
                    ImageFlag = Visibility.Visible;
                    ImagePlayer.Visibility = Visibility.Visible;
                    imagePlayerNext.Visibility = Visibility.Hidden;
                    imageTran.Visibility = Visibility.Hidden;
                    Opacity = 1;
                    foreach (PlaySourceVo playSourceVo in obj.PlaySources)
                    {
                        currentProgramList.Add(playSourceVo.SouceItem);
                    }
                    if (String.IsNullOrEmpty(currentProgramList[0].DisplayMode) || currentProgramList[0].DisplayMode.Equals("1"))
                    {
                        //全屏
                        //CurrentWindow.WindowState = WindowState.Maximized;
                        //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                        //CurrentWindow.WindowStyle = WindowStyle.None;
                        if (null != ImagePlayer)
                        {
                            ImagePlayer.Width = 230;
                            ImagePlayer.Height = 200;
                            ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;

                        }

                    }
                    if (!String.IsNullOrEmpty(currentProgramList[0].DisplayMode) && currentProgramList[0].DisplayMode.Equals("2"))
                    {
                        //视屏自身生比例
                        ImagePlayer.Width = 230;
                        ImagePlayer.Height = 200;
                        ImagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                    }
                    if (!String.IsNullOrEmpty(currentProgramList[0].DisplayMode) && currentProgramList[0].DisplayMode.Equals("3"))
                    {
                        //16:9
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 16 / 9);
                        }

                        ImagePlayer.Height = newHeight;
                        ImagePlayer.Width = newWidth;
                        ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    if (!String.IsNullOrEmpty(currentProgramList[0].DisplayMode) && currentProgramList[0].DisplayMode.Equals("4"))
                    {
                        //4:3
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 4 / 3);
                        }

                        ImagePlayer.Height = newHeight;
                        ImagePlayer.Width = newWidth;
                        ImagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    ImagePlayer.Source = WriteFileUtil.Capture();
                    timer2.Interval = TimeSpan.FromMilliseconds(50);
                    timer2.Start();
                    VideoPlayer.Visibility = Visibility.Hidden;
                    WebBrowser.Visibility = Visibility.Hidden;
                    if (null != WebBrowser && WebBrowser.Children.Count > 0)
                    {
                        WebBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
                    }
                    VideoPlayer.Source = null;
                    VideoPlayer.Stop();
                    if (null != imagePlayerNext)
                    {
                        imagePlayerNext.Visibility = Visibility.Hidden;
                        imagePlayerNext.Source = null;
                    }
                    if (null != imageTran)
                    {
                        imageTran.Content = null;
                        imageTran.Visibility = Visibility.Hidden;
                    }
                    imageCenter(imagePlayer);
                    break;
                case "7":
                    if (null != VideoPlayer)
                    {
                        VideoPlayer.Stop();
                        VideoPlayer.Source = null;
                        VideoPlayer.Visibility = Visibility.Hidden;
                    }
                    if (null != WebBrowser && WebBrowser.Children.Count > 0)
                    {
                        webBrowser.Children.RemoveAt(WebBrowser.Children.Count - 1);
                    }
                    if (null != ImagePlayer)
                    {
                        ImagePlayer.Visibility = Visibility.Hidden;
                        ImagePlayer.Source = null;
                    }
                    if (null != imagePlayerNext)
                    {
                        imagePlayerNext.Visibility = Visibility.Hidden;
                        imagePlayerNext.Source = null;
                    }
                    if (null != imageTran)
                    {
                        imageTran.Content = null;
                        imageTran.Visibility = Visibility.Hidden;
                    }
                    timer.Stop();
                    timer1.Stop();
                    timer2.Stop();
                    break;
            }

        }
        private int imageIndex = 0;
        private void Timer_Tick(object sender, EventArgs e)
        {

            timer.Stop();

            if (null == exitModes || exitModes.Count <= 0)
            {
                return;
            }
            if (imageIndex >= imagePaths.Count)
            {
                imageIndex = 0;
            }
            exitMethod = exitModes[imageIndex];
            if (string.IsNullOrEmpty(exitMethod))
            {
                return;
            }
            switch (exitMethod)
            {
                case "1":
                    imageIndex++;
                    if (imageIndex >= imagePaths.Count)
                    {
                        imageIndex = 0;
                    }
                    if (imageIndex % 2 == 0)
                    {

                        NextFadeOut();
                        showImage();
                    }
                    else
                    {
                        FadeOut();
                        showNextImage();
                    }
                    break;
                case "2":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideLeftImageIn();
                        SlideRightNextImageOut();
                    }
                    else
                    {
                        SlideRightImageOut();
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideLeftNextImageIn();
                    }
                    break;
                case "3":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideLeftNextImageOut();
                        SlideRightImageIn();
                    }
                    else
                    {
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideLeftImageOut();
                        SlideRightNextImageIn();
                    }
                    break;
                case "4":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideUpImageIn();
                        SlideUpNextImageOut();
                    }
                    else
                    {
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideUpNextImageIn();
                        SlideUpImageOut();
                    }
                    break;
                case "5":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideDownImageIn();
                        SlideDownNextImageOut();
                    }
                    else
                    {
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideDownNextImageIn();
                        SlideDownImageOut();
                    }
                    break;
                case "6":
                    imageIndex++;
                    if (imageIndex >= imagePaths.Count)
                    {
                        imageIndex = 0;
                    }
                    ShutterImageIn();
                    break;
                case "7":
                    ++imageIndex;
                    if (imageIndex >= imagePaths.Count)
                    {
                        imageIndex = 0;
                    }
                    if (imageIndex % 2 == 0)
                    {

                        ScaleNextImageOut();
                        imagePlayer.Visibility = Visibility.Visible;
                        ScaleShowImage();

                    }
                    else
                    {



                        ScaleImageOut();
                        ScaleShowNextImage();

                    }

                    break;
                case "8":
                    RandomImage();
                    break;
                default:
                    imagePlayerNext.Visibility = Visibility.Hidden;
                    imagePlayer.Visibility = Visibility.Visible;
                    imageIndex++;
                    if (imageIndex >= imagePaths.Count)
                    {
                        imageIndex = 0;
                    }
                    displayMode = displayModes[imageIndex];
                    ImageSrc = imagePaths[imageIndex];
                    if (displayMode.Equals("1"))
                    {
                        //全屏
                        //CurrentWindow.WindowState = WindowState.Maximized;
                        //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                        //CurrentWindow.WindowStyle = WindowStyle.None;

                        imagePlayer.Width = screenVo.Width;
                        imagePlayer.Height = screenVo.Height;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                    }
                    if (displayMode.Equals("2"))
                    {
                        //视屏自身生比例
                        imagePlayer.Width = screenVo.Width;
                        imagePlayer.Height = screenVo.Height;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                    }
                    if (displayMode.Equals("3"))
                    {
                        //16:9
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 16 / 9);
                        }
                        imagePlayer.Width = newWidth;
                        imagePlayer.Height = newHeight;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    if (displayMode.Equals("4"))
                    {
                        //4:3
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 4 / 3);
                        }
                        imagePlayer.Width = newWidth;
                        imagePlayer.Height = newHeight;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                    imageCenter(imagePlayer);
                    break;
            }
            timer.Interval = TimeSpan.FromSeconds(stopTimes[imageIndex]);
            timer.Start();

        }

        public List<string> getImageList(string folderPath)
        {

            List<String> imageList = new List<string>();
            try
            {
                // 获取文件夹中所有文件的列表
                string[] files = Directory.GetFiles(folderPath);

                foreach (string file in files)
                {
                    if (IsImageFile(file))
                    {
                        imageList.Add(file);
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error reading folder content: " + ex.Message);
            }
            return imageList;
        }

        public bool IsImageFile(string filePath)
        {
            try
            {
                using (var image = new Bitmap(filePath))
                    return true;
            }
            catch (Exception ex) when (ex is ArgumentNullException || ex is NotSupportedException)
            {
                return false;
            }
        }
        //淡入淡出
        private void FadeIn()
        {
            var fadeInAnimation = new DoubleAnimation(0.5, 1, TimeSpan.FromSeconds(1));
            imagePlayer.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
        }

        private void FadeOut()
        {
            BringToFront(imagePlayer);
            var fadeInAnimation = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(1));
            fadeInAnimation.Completed += (s, arg) =>
            {


                imagePlayer.Visibility = Visibility.Hidden;
                var fadeInAnimation1 = new DoubleAnimation(0.7, 1, TimeSpan.FromSeconds(0));
                imagePlayer.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation1);


            };
            imagePlayer.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);


        }

        private void NextFadeIn()
        {
            var fadeInAnimation = new DoubleAnimation(0.6, 1, TimeSpan.FromSeconds(1));
            fadeInAnimation.Completed += (s, arg) =>
            {

                //imagePlayer.Opacity = 0.2;


            };
            imagePlayerNext.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
        }

        private void NextFadeOut()
        {
            BringToFront(imagePlayerNext);
            var fadeInAnimation = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(1));
            fadeInAnimation.Completed += (s, arg) =>
            {

                imagePlayerNext.Visibility = Visibility.Hidden;
                var fadeInAnimation1 = new DoubleAnimation(0.7, 1, TimeSpan.FromSeconds(0));
                imagePlayerNext.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation1);

            };
            imagePlayerNext.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
        }

        private void showImage()
        {


            displayMode = displayModes[imageIndex];
            if (displayMode.Equals("1"))
            {
                //全屏
                //CurrentWindow.WindowState = WindowState.Maximized;
                //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                //CurrentWindow.WindowStyle = WindowStyle.None;

                imagePlayer.Width = screenVo.Width;
                imagePlayer.Height = screenVo.Height;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



            }
            if (displayMode.Equals("2"))
            {
                //视屏自身生比例
                imagePlayer.Width = screenVo.Width;
                imagePlayer.Height = screenVo.Height;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
            }
            if (displayMode.Equals("3"))
            {
                //16:9
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 16 / 9);
                }
                imagePlayer.Width = newWidth;
                imagePlayer.Height = newHeight;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
            }
            if (displayMode.Equals("4"))
            {
                //4:3
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 4 / 3);
                }
                imagePlayer.Width = newWidth;
                imagePlayer.Height = newHeight;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
            }
            imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
            imagePlayer.Visibility = Visibility.Visible;
            imageCenter(imagePlayer);

        }

        private void showNextImage()
        {
            //imagePlayerNext.Opacity = 1.0;
            displayMode = displayModes[imageIndex];
            if (displayMode.Equals("1"))
            {
                //全屏
                //CurrentWindow.WindowState = WindowState.Maximized;
                //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                //CurrentWindow.WindowStyle = WindowStyle.None;

                imagePlayerNext.Width = screenVo.Width;
                imagePlayerNext.Height = screenVo.Height;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



            }
            if (displayMode.Equals("2"))
            {
                //视屏自身生比例
                imagePlayerNext.Width = screenVo.Width;
                imagePlayerNext.Height = screenVo.Height;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
            }
            if (displayMode.Equals("3"))
            {
                //16:9
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 16 / 9);
                }
                imagePlayerNext.Width = newWidth;
                imagePlayerNext.Height = newHeight;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
            }
            if (displayMode.Equals("4"))
            {
                //4:3
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 4 / 3);
                }
                imagePlayerNext.Width = newWidth;
                imagePlayerNext.Height = newHeight;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
            }
            imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
            imagePlayerNext.Visibility = Visibility.Visible;
            imageCenter(imagePlayerNext);
        }
        //左移入
        private void SlideLeftImageIn()
        {
            // 设置动画目标属性为X轴的TranslateTransform

            DoubleAnimation slideInAnimation = new DoubleAnimation(-screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {

                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayerNext.Visibility = Visibility.Hidden;
                imageCenter(imagePlayerNext);
            };

            translateTransform.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }

        private void SlideRightImageOut()
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, screenVo.Width, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayer.Visibility = Visibility.Hidden;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransform.BeginAnimation(TranslateTransform.XProperty, slideInAnimation1);
            };
            translateTransform.X = 0;
            translateTransform.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }
        private void SlideLeftNextImageIn()
        {
            // 设置动画目标属性为X轴的TranslateTransform

            DoubleAnimation slideInAnimation = new DoubleAnimation(-screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayer.Visibility = Visibility.Hidden;
                imageCenter(imagePlayer);
                translateTransformNext.X = 0; // Reset translation after animation
            };
            translateTransformNext.X = 0;
            translateTransformNext.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }

        private void SlideRightNextImageOut()
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, screenVo.Width, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayerNext.Visibility = Visibility.Hidden;

                DoubleAnimation slideInAnimation1 = new DoubleAnimation(screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(1)));
                translateTransformNext.BeginAnimation(TranslateTransform.XProperty, slideInAnimation1);
            };
            translateTransformNext.X = 0;
            translateTransformNext.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }




        //右移入
        private void SlideRightImageIn()
        {
            // 设置动画目标属性为X轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {

                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayerNext.Visibility = Visibility.Hidden;
                imageCenter(imagePlayerNext);
                translateTransform.X = 0; // Reset translation after animation
            };
            translateTransform.X = 0;
            translateTransform.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }

        private void SlideRightNextImageIn()
        {
            // 设置动画目标属性为X轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(1)));

            slideInAnimation.Completed += (s, arg) =>
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayer.Visibility = Visibility.Hidden;
                imageCenter(imagePlayer);
                translateTransformNext.X = 0;
            };
            translateTransformNext.X = 0;
            translateTransformNext.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }
        private void SlideLeftImageOut()
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, -screenVo.Width, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayer.Visibility = Visibility.Hidden;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(-screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransform.BeginAnimation(TranslateTransform.XProperty, slideInAnimation1);
            };
            translateTransform.X = 0;
            translateTransform.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }

        private void SlideLeftNextImageOut()
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, -screenVo.Width, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayerNext.Visibility = Visibility.Hidden;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(-screenVo.Width, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransformNext.BeginAnimation(TranslateTransform.XProperty, slideInAnimation1);
            };
            translateTransformNext.X = 0;
            translateTransformNext.BeginAnimation(TranslateTransform.XProperty, slideInAnimation);
        }
        //上移入
        private void SlideUpImageIn()
        {
            // 设置动画目标属性为y轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(-screenVo.Height, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                    translateTransform.Y = 0;
                }
                imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayerNext.Visibility = Visibility.Hidden;
                imageCenter(imagePlayerNext);
            };
            translateTransform.Y = 0;
            translateTransform.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }
        private void SlideUpImageOut()
        {
            // 设置动画目标属性为y轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, screenVo.Height, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayer.Visibility = Visibility.Hidden;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(screenVo.Height, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransform.BeginAnimation(TranslateTransform.YProperty, slideInAnimation1);
            };
            translateTransform.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }

        private void SlideUpNextImageIn()
        {
            // 设置动画目标属性为y轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(-screenVo.Height, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayer.Visibility = Visibility.Hidden;
                imageCenter(imagePlayer);
                translateTransformNext.Y = 0;
            };
            translateTransformNext.Y = 0;
            translateTransformNext.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }

        private void SlideUpNextImageOut()
        {
            // 设置动画目标属性为y轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, screenVo.Height, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayerNext.Visibility = Visibility.Hidden;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(screenVo.Height, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransformNext.BeginAnimation(TranslateTransform.YProperty, slideInAnimation1);
            };
            translateTransformNext.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }

        //下移入
        private void SlideDownImageIn()
        {
            // 设置动画目标属性为X轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(imagePlayer.Height, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayerNext.Visibility = Visibility.Hidden;
                imageCenter(imagePlayerNext);
                translateTransform.Y = 0;
            };
            translateTransform.Y = 0;
            translateTransform.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }

        private void SlideDownImageOut()
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, -imagePlayer.Height, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayer.Visibility = Visibility.Visible;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(-imagePlayer.Height, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransform.BeginAnimation(TranslateTransform.YProperty, slideInAnimation1);

            };

            translateTransform.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }

        private void SlideDownNextImageOut()
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation(0, -imagePlayer.Height, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imagePlayerNext.Visibility = Visibility.Visible;
                DoubleAnimation slideInAnimation1 = new DoubleAnimation(-imagePlayer.Height, 0, new Duration(TimeSpan.FromSeconds(0)));
                translateTransformNext.BeginAnimation(TranslateTransform.YProperty, slideInAnimation1);
            };
            translateTransformNext.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }

        private void SlideDownNextImageIn()
        {
            // 设置动画目标属性为X轴的TranslateTransform
            DoubleAnimation slideInAnimation = new DoubleAnimation(screenVo.Height, 0, new Duration(TimeSpan.FromSeconds(1)));
            slideInAnimation.Completed += (s, arg) =>
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayer.Visibility = Visibility.Hidden;
                imageCenter(imagePlayer);
                translateTransformNext.Y = 0;
            };
            translateTransformNext.Y = 0;
            translateTransformNext.BeginAnimation(TranslateTransform.YProperty, slideInAnimation);
        }
        //缩放
        private void ScaleImageIn()
        {

            DoubleAnimation scaleInAnimation = new DoubleAnimation(0.6, 1, new Duration(TimeSpan.FromSeconds(2)));
            DoubleAnimation scaleInAnimationX = new DoubleAnimation(0.6, 1, new Duration(TimeSpan.FromSeconds(2)));
            scaleInAnimation.FillBehavior = FillBehavior.HoldEnd;
            scaleInAnimationX.FillBehavior = FillBehavior.HoldEnd;
            scaleTransform.CenterX = imagePlayer.Width / 2;
            scaleTransform.CenterY = imagePlayer.Height / 2;
            scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnimationX);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnimation);

        }



        private void ScaleNextImageIn()
        {
            DoubleAnimation scaleInAnimation = new DoubleAnimation(0.6, 1, new Duration(TimeSpan.FromSeconds(1)));
            DoubleAnimation scaleInAnimationX = new DoubleAnimation(0.6, 1, new Duration(TimeSpan.FromSeconds(1)));
            scaleInAnimation.Completed += (s, e) => scaleTransform.ScaleX = 1.0;
            scaleInAnimationX.Completed += (s, e) =>
            {
                scaleTransform.ScaleY = 1.0;
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                displayMode = displayModes[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
                imagePlayer.Visibility = Visibility.Hidden;
            };
            scaleTransformNext.CenterX = imagePlayer.Width / 2;
            scaleTransformNext.CenterY = imagePlayer.Height / 2;
            scaleTransformNext.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnimationX);
            scaleTransformNext.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnimation);

        }
        private void ScaleImageOut()
        {

            BringToFront(imagePlayer);
            DoubleAnimation scaleInAnimation = new DoubleAnimation(1, 0.4, new Duration(TimeSpan.FromSeconds(1)));
            DoubleAnimation scaleInAnimationX = new DoubleAnimation(1, 0.4, new Duration(TimeSpan.FromSeconds(1)));
            scaleInAnimationX.Completed += (e, arg) =>
            {

                imagePlayer.Visibility = Visibility.Hidden;
                DoubleAnimation scaleInAnimation1 = new DoubleAnimation(0.4, 1, new Duration(TimeSpan.FromSeconds(0)));
                DoubleAnimation scaleInAnimationX1 = new DoubleAnimation(0.4, 1, new Duration(TimeSpan.FromSeconds(0)));
                scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnimationX1);
                scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnimation1);

            };
            scaleTransform.CenterX = imagePlayer.Width / 2;
            scaleTransform.CenterY = imagePlayer.Height / 2;
            scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnimationX);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnimation);
            //ScaleShowNextImage();

        }

        private void ScaleNextImageOut()
        {
            BringToFront(imagePlayerNext);
            DoubleAnimation scaleInAnimation = new DoubleAnimation(1, 0.4, new Duration(TimeSpan.FromSeconds(1)));
            DoubleAnimation scaleInAnimationX = new DoubleAnimation(1, 0.4, new Duration(TimeSpan.FromSeconds(1)));
            scaleInAnimationX.Completed += (e, arg) =>
            {
                imagePlayerNext.Visibility = Visibility.Hidden;
                DoubleAnimation scaleInAnimation1 = new DoubleAnimation(0.4, 1, new Duration(TimeSpan.FromSeconds(0)));
                DoubleAnimation scaleInAnimationX1 = new DoubleAnimation(0.4, 1, new Duration(TimeSpan.FromSeconds(0)));
                scaleTransformNext.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnimationX1);
                scaleTransformNext.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnimation1);
            };
            scaleTransformNext.CenterX = imagePlayer.Width / 2;
            scaleTransformNext.CenterY = imagePlayer.Height / 2;
            scaleTransformNext.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnimationX);
            scaleTransformNext.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnimation);
        }

        public void BringToFront(Image element)//图片置于最顶层显示
        {
            //计算
            if (element == null) return;


            Canvas parent = element.Parent as Canvas;
            if (parent == null) return;


            var maxZ = parent.Children.OfType<UIElement>()//linq语句，取Zindex的最大值
              .Where(x => x != element)
              .Select(x => Canvas.GetZIndex(x))
              .Max();
            Canvas.SetZIndex(element, maxZ + 1);
        }


        private void ScaleShowNextImage()
        {
            imagePlayerNext.Visibility = Visibility.Hidden;
            displayMode = displayModes[imageIndex];
            if (displayMode.Equals("1"))
            {
                //全屏
                //CurrentWindow.WindowState = WindowState.Maximized;
                //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                //CurrentWindow.WindowStyle = WindowStyle.None;

                imagePlayerNext.Width = screenVo.Width;
                imagePlayerNext.Height = screenVo.Height;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



            }
            if (displayMode.Equals("2"))
            {
                //视屏自身生比例
                imagePlayerNext.Width = screenVo.Width;
                imagePlayerNext.Height = screenVo.Height;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
            }
            if (displayMode.Equals("3"))
            {
                //16:9
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 16 / 9);
                }
                imagePlayerNext.Width = newWidth;
                imagePlayerNext.Height = newHeight;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
            }
            if (displayMode.Equals("4"))
            {
                //4:3
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 4 / 3);
                }
                imagePlayerNext.Width = newWidth;
                imagePlayerNext.Height = newHeight;
                imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
            }
            imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
            imagePlayerNext.Visibility = Visibility.Visible;
            imageCenter(imagePlayerNext);
            //DoubleAnimation scaleInAnimation = new DoubleAnimation(0.5, 1, new Duration(TimeSpan.FromMilliseconds(50)));
            //imagePlayerNext.BeginAnimation(UIElement.OpacityProperty, scaleInAnimation);
        }

        private void ScaleShowImage()
        {
            displayMode = displayModes[imageIndex];
            if (displayMode.Equals("1"))
            {
                //全屏
                //CurrentWindow.WindowState = WindowState.Maximized;
                //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                //CurrentWindow.WindowStyle = WindowStyle.None;

                imagePlayer.Width = screenVo.Width;
                imagePlayer.Height = screenVo.Height;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



            }
            if (displayMode.Equals("2"))
            {
                //视屏自身生比例
                imagePlayer.Width = screenVo.Width;
                imagePlayer.Height = screenVo.Height;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
            }
            if (displayMode.Equals("3"))
            {
                //16:9
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 16 / 9);
                }
                imagePlayer.Width = newWidth;
                imagePlayer.Height = newHeight;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
            }
            if (displayMode.Equals("4"))
            {
                //4:3
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 4 / 3);
                }
                imagePlayer.Width = newWidth;
                imagePlayer.Height = newHeight;
                imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
            }
            imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);
            imagePlayer.Visibility = Visibility.Visible;
            imageCenter(imagePlayer);

        }
        //百叶窗
        private PathGeometry pg = null;
        private DispatcherTimer timer1 = new DispatcherTimer();
        //设置矩形的大小
        double size = 100;
        //矩形的初始宽度
        double size1 = 0;
        //百叶窗
        private TransitionElement imageTran;
        private void ShutterImageIn()
        {
            imagePlayer.Visibility = Visibility.Hidden;
            imagePlayerNext.Visibility = Visibility.Hidden;
            imageTran.Visibility = Visibility.Visible;
            Transitionals.Transitions.VerticalBlindsTransition t = new Transitionals.Transitions.VerticalBlindsTransition();
            imageTran.Transition = t;
            imageTran.Loaded += FillImage;
            Image imageNew = new Image();
            displayMode = displayModes[imageIndex];
            if (displayMode.Equals("1"))
            {
                //全屏
                //CurrentWindow.WindowState = WindowState.Maximized;
                //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                //CurrentWindow.WindowStyle = WindowStyle.None;

                imageNew.Width = screenVo.Width;
                imageNew.Height = screenVo.Height;
                imageNew.Stretch = System.Windows.Media.Stretch.Fill;



            }
            if (displayMode.Equals("2"))
            {
                //视屏自身生比例
                imageNew.Width = screenVo.Width;
                imageNew.Height = screenVo.Height;
                imageNew.Stretch = System.Windows.Media.Stretch.Uniform;
            }
            if (displayMode.Equals("3"))
            {
                //16:9
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 16 / 9);
                }
                imageNew.Width = newWidth;
                imageNew.Height = newHeight;
                imageNew.Stretch = System.Windows.Media.Stretch.Fill;
            }
            if (displayMode.Equals("4"))
            {
                //4:3
                int newWidth = screenVo.Width;
                int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                if (newHeight > screenVo.Height)
                {
                    // If the height exceeds the given height, reduce the width
                    newHeight = screenVo.Height;
                    newWidth = (int)(newHeight * 4 / 3);
                }
                imageNew.Width = newWidth;
                imageNew.Height = newHeight;
                imageNew.Stretch = System.Windows.Media.Stretch.Fill;
            }
            imageNew.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(imagePaths[imageIndex]);

            imageTran.Content = imageNew;
        }

        private void FillImage(object sender, RoutedEventArgs e)
        {
            if (imageIndex % 2 == 0)
            {

                imagePlayerNext.Visibility = Visibility.Hidden;
                imagePlayer.Visibility = Visibility.Visible;

                displayMode = displayModes[imageIndex];
                ImageSrc = imagePaths[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayer.Width = screenVo.Width;
                    imagePlayer.Height = screenVo.Height;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayer.Width = newWidth;
                    imagePlayer.Height = newHeight;
                    imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                imageCenter(imagePlayer);

            }
            else
            {



                imagePlayerNext.Visibility = Visibility.Visible;
                imagePlayer.Visibility = Visibility.Hidden;

                displayMode = displayModes[imageIndex];
                ImageSrc = imagePaths[imageIndex];
                if (displayMode.Equals("1"))
                {
                    //全屏
                    //CurrentWindow.WindowState = WindowState.Maximized;
                    //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                    //CurrentWindow.WindowStyle = WindowStyle.None;

                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                }
                if (displayMode.Equals("2"))
                {
                    //视屏自身生比例
                    imagePlayerNext.Width = screenVo.Width;
                    imagePlayerNext.Height = screenVo.Height;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                }
                if (displayMode.Equals("3"))
                {
                    //16:9
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 16 / 9);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                if (displayMode.Equals("4"))
                {
                    //4:3
                    int newWidth = screenVo.Width;
                    int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                    if (newHeight > screenVo.Height)
                    {
                        // If the height exceeds the given height, reduce the width
                        newHeight = screenVo.Height;
                        newWidth = (int)(newHeight * 4 / 3);
                    }
                    imagePlayerNext.Width = newWidth;
                    imagePlayerNext.Height = newHeight;
                    imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                }
                imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                imageCenter(imagePlayerNext);

            }
        }

        private List<string> randomExitModes = new List<string>() { "0", "1", "2", "3", "4", "5", "6", "7" };
        private int randomIndex = 0;
        private void InitRandomImage()
        {
            randomIndex = 0;
            //int randomIndex = new Random().Next(randomExitModes.Count); // 生成一个随机索引
            string randomExitMethod = randomExitModes[randomIndex]; // 获取随机元素
            lastExitMode = randomExitMethod;
            switch (randomExitMethod)
            {
                case "1":
                    Opacity = 0.2;
                    FadeIn();
                    break;
                case "2":
                    Opacity = 1;
                    SlideLeftImageIn();
                    break;
                case "3":
                    Opacity = 1;
                    SlideRightImageIn();
                    break;
                case "4":
                    Opacity = 1;
                    SlideUpImageIn();
                    break;
                case "5":
                    Opacity = 1;
                    SlideDownImageIn();
                    break;
                case "6":
                    Opacity = 1;
                    ShutterImageIn();
                    break;
                case "7":
                    Opacity = 1;
                    ScaleImageIn();
                    break;
                default:
                    Opacity = 1;
                    break;

            }
            imageIndex = 0;
            timer.Start();
        }
        private string lastExitMode;
        private void RandomImage()
        {
            //int randomIndex = new Random().Next(randomExitModes.Count); // 生成一个随机索引
            randomIndex = (randomIndex + 1) % randomExitModes.Count;
            string randomExitMethod = randomExitModes[randomIndex]; // 获取随机元素

            if ("1".Equals(lastExitMode) || "6".Equals(lastExitMode) || "7".Equals(lastExitMode) || "0".Equals(lastExitMode))
            {
                imageIndex = (imageIndex + 1) % imagePaths.Count;
                if (imageIndex % 2 == 0)
                {

                    displayMode = displayModes[imageIndex];
                    ImageSrc = imagePaths[imageIndex];
                    if (displayMode.Equals("1"))
                    {
                        //全屏
                        //CurrentWindow.WindowState = WindowState.Maximized;
                        //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                        //CurrentWindow.WindowStyle = WindowStyle.None;

                        imagePlayer.Width = screenVo.Width;
                        imagePlayer.Height = screenVo.Height;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                    }
                    if (displayMode.Equals("2"))
                    {
                        //视屏自身生比例
                        imagePlayer.Width = screenVo.Width;
                        imagePlayer.Height = screenVo.Height;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                    }
                    if (displayMode.Equals("3"))
                    {
                        //16:9
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 16 / 9);
                        }
                        imagePlayer.Width = newWidth;
                        imagePlayer.Height = newHeight;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    if (displayMode.Equals("4"))
                    {
                        //4:3
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 4 / 3);
                        }
                        imagePlayer.Width = newWidth;
                        imagePlayer.Height = newHeight;
                        imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                    imageCenter(imagePlayer);

                }
                else
                {





                    displayMode = displayModes[imageIndex];
                    ImageSrc = imagePaths[imageIndex];
                    if (displayMode.Equals("1"))
                    {
                        //全屏
                        //CurrentWindow.WindowState = WindowState.Maximized;
                        //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                        //CurrentWindow.WindowStyle = WindowStyle.None;

                        imagePlayerNext.Width = screenVo.Width;
                        imagePlayerNext.Height = screenVo.Height;
                        imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                    }
                    if (displayMode.Equals("2"))
                    {
                        //视屏自身生比例
                        imagePlayerNext.Width = screenVo.Width;
                        imagePlayerNext.Height = screenVo.Height;
                        imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                    }
                    if (displayMode.Equals("3"))
                    {
                        //16:9
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 16 / 9);
                        }
                        imagePlayerNext.Width = newWidth;
                        imagePlayerNext.Height = newHeight;
                        imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    if (displayMode.Equals("4"))
                    {
                        //4:3
                        int newWidth = screenVo.Width;
                        int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                        if (newHeight > screenVo.Height)
                        {
                            // If the height exceeds the given height, reduce the width
                            newHeight = screenVo.Height;
                            newWidth = (int)(newHeight * 4 / 3);
                        }
                        imagePlayerNext.Width = newWidth;
                        imagePlayerNext.Height = newHeight;
                        imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                    }
                    imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                    imageCenter(imagePlayerNext);

                }

            }
            if ("6".Equals(lastExitMode) && !"6".Equals(randomExitMethod))
            {
                imageTran.Visibility = Visibility.Hidden;
                if (imageIndex % 2 == 0)
                {
                    imagePlayer.Visibility = Visibility.Visible;
                    BringToFront(imagePlayerNext);

                }
                else
                {
                    imagePlayerNext.Visibility = Visibility.Visible;
                    BringToFront(imagePlayer);

                }
            }
            switch (randomExitMethod)
            {
                case "1":
                    if (imageIndex % 2 == 0)
                    {
                        showImage();
                        NextFadeOut();
                        BringToFront(imagePlayer);
                    }
                    else
                    {
                        showNextImage();
                        FadeOut();
                        BringToFront(imagePlayerNext);

                    }
                    break;
                case "2":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideLeftImageIn();
                        SlideRightNextImageOut();
                        BringToFront(imagePlayer);
                    }
                    else
                    {
                        SlideRightImageOut();
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideLeftNextImageIn();
                        BringToFront(imagePlayerNext);
                    }
                    break;
                case "3":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideLeftNextImageOut();
                        SlideRightImageIn();
                        BringToFront(imagePlayer);
                    }
                    else
                    {
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideLeftImageOut();
                        SlideRightNextImageIn();
                        BringToFront(imagePlayerNext);
                    }
                    break;
                case "4":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideUpImageIn();
                        SlideUpNextImageOut();
                        BringToFront(imagePlayer);
                    }
                    else
                    {
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideUpNextImageIn();
                        SlideUpImageOut();
                        BringToFront(imagePlayerNext);
                    }
                    break;
                case "5":
                    if (imageIndex % 2 == 0)
                    {
                        imagePlayer.Visibility = Visibility.Visible;
                        SlideDownImageIn();
                        SlideDownNextImageOut();
                        BringToFront(imagePlayer);
                    }
                    else
                    {
                        imagePlayerNext.Visibility = Visibility.Visible;
                        SlideDownNextImageIn();
                        SlideDownImageOut();
                        BringToFront(imagePlayerNext);
                    }
                    break;
                case "6":
                    ShutterImageIn();
                    break;
                case "7":

                    if (imageIndex % 2 == 0)
                    {

                        ScaleNextImageOut();
                        ScaleShowImage();

                    }
                    else
                    {



                        ScaleImageOut();
                        ScaleShowNextImage();

                    }

                    break;
                default:
                    if (imageIndex % 2 == 0)
                    {

                        imagePlayerNext.Visibility = Visibility.Hidden;
                        imagePlayer.Visibility = Visibility.Visible;

                        displayMode = displayModes[imageIndex];
                        ImageSrc = imagePaths[imageIndex];
                        if (displayMode.Equals("1"))
                        {
                            //全屏
                            //CurrentWindow.WindowState = WindowState.Maximized;
                            //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                            //CurrentWindow.WindowStyle = WindowStyle.None;

                            imagePlayer.Width = screenVo.Width;
                            imagePlayer.Height = screenVo.Height;
                            imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;



                        }
                        if (displayMode.Equals("2"))
                        {
                            //视屏自身生比例
                            imagePlayer.Width = screenVo.Width;
                            imagePlayer.Height = screenVo.Height;
                            imagePlayer.Stretch = System.Windows.Media.Stretch.Uniform;
                        }
                        if (displayMode.Equals("3"))
                        {
                            //16:9
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 16 / 9);
                            }
                            imagePlayer.Width = newWidth;
                            imagePlayer.Height = newHeight;
                            imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        if (displayMode.Equals("4"))
                        {
                            //4:3
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 4 / 3);
                            }
                            imagePlayer.Width = newWidth;
                            imagePlayer.Height = newHeight;
                            imagePlayer.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        imagePlayer.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                        imageCenter(imagePlayer);
                        BringToFront(imagePlayer);

                    }
                    else
                    {



                        imagePlayerNext.Visibility = Visibility.Visible;
                        imagePlayer.Visibility = Visibility.Hidden;

                        displayMode = displayModes[imageIndex];
                        ImageSrc = imagePaths[imageIndex];
                        if (displayMode.Equals("1"))
                        {
                            //全屏
                            //CurrentWindow.WindowState = WindowState.Maximized;
                            //CurrentWindow.ResizeMode = ResizeMode.NoResize;
                            //CurrentWindow.WindowStyle = WindowStyle.None;

                            imagePlayerNext.Width = screenVo.Width;
                            imagePlayerNext.Height = screenVo.Height;
                            imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;



                        }
                        if (displayMode.Equals("2"))
                        {
                            //视屏自身生比例
                            imagePlayerNext.Width = screenVo.Width;
                            imagePlayerNext.Height = screenVo.Height;
                            imagePlayerNext.Stretch = System.Windows.Media.Stretch.Uniform;
                        }
                        if (displayMode.Equals("3"))
                        {
                            //16:9
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 9 / 16); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 16 / 9);
                            }
                            imagePlayerNext.Width = newWidth;
                            imagePlayerNext.Height = newHeight;
                            imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        if (displayMode.Equals("4"))
                        {
                            //4:3
                            int newWidth = screenVo.Width;
                            int newHeight = (int)(screenVo.Width * 3 / 4); // 4:3 aspect ratio

                            if (newHeight > screenVo.Height)
                            {
                                // If the height exceeds the given height, reduce the width
                                newHeight = screenVo.Height;
                                newWidth = (int)(newHeight * 4 / 3);
                            }
                            imagePlayerNext.Width = newWidth;
                            imagePlayerNext.Height = newHeight;
                            imagePlayerNext.Stretch = System.Windows.Media.Stretch.Fill;
                        }
                        imagePlayerNext.Source = (ImageSource)new ImageSourceConverter().ConvertFromString(ImageSrc);
                        BringToFront(imagePlayerNext);
                        imageCenter(imagePlayerNext);

                    }

                    break;
            }
            lastExitMode = randomExitMethod;
        }


        private void imageCenter(Image element)
        {
            if (element == null) return;
            Canvas.SetLeft(element, (screenVo.Width - element.Width) / 2);
            Canvas.SetTop(element, (screenVo.Height - element.Height) / 2);

        }

    }
}
